import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_1800/tools/AppUtil.dart';
import 'package:video_player/video_player.dart';

typedef PageChanged = void Function(int index);

class VideoShow extends StatefulWidget {
  final String? url; //图片列表

  const VideoShow(this.url, {Key? key});

  @override
  _VideoShowState createState() => _VideoShowState();
}

class _VideoShowState extends State<VideoShow> {
  late VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(widget.url!)
      ..initialize().then((_) {
        _controller.play();
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });
  }

  @override
  void dispose() {
    super.dispose();
    _controller.pause();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        extendBodyBehindAppBar: true,
        backgroundColor: Colors.black,
        appBar: AppBar(
            title: const Text("", style: TextStyle(color: Colors.white)),
            centerTitle: true,
            elevation: 0.0,
            backgroundColor: Colors.black,
            shadowColor: Colors.white,
            toolbarOpacity: 1,
            systemOverlayStyle: SystemUiOverlayStyle.light
                .copyWith(statusBarColor: Colors.black),
            leading: IconButton(
              icon: const Icon(
                Icons.arrow_back_ios,
                color: Colors.white,
              ),
              onPressed: () {
                AppUtil.back();
              },
            )),
        body: GestureDetector(
          onTap: () {
            SystemUiOverlayStyle systemUiOverlayStyle =
                const SystemUiOverlayStyle(
                    statusBarColor: Colors.white,
                    /*状态栏 背景透明*/
                    systemNavigationBarColor: Colors.white //底部navigationBar背景颜色
                    );
            SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
            AppUtil.back();
          },
          child: _controller.value.isInitialized
              ? AspectRatio(
                  aspectRatio: _controller.value.aspectRatio,
                  child: VideoPlayer(_controller),
                )
              : Container(),
        ));
  }
}
